# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
pkgname=hipify-clang
pkgver=5.7.1
pkgrel=1
pkgdesc='Convert CUDA to Portable C++ Code'
arch=('loong64' 'x86_64')
url='https://rocm.docs.amd.com/projects/HIPIFY/en/latest'
license=('MIT')
depends=('rocm-llvm' 'cuda')
makedepends=('cmake')
_git='https://github.com/ROCm-Developer-Tools/HIPIFY'
source=("${pkgname}-${pkgver}.tar.gz::$_git/archive/rocm-$pkgver.tar.gz"
        "hipify-fix-install-cmake.patch")
sha256sums=('43121e62233dab010ab686d6805bc2d3163f0dc5e89cc503d50c4bcd59eeb394'
            '64d422e402b2f93cc83df2b762cf9f06f2b9b358de2643abff78298f875acd0a')
options=(!lto)
_dirname="$(basename "$_git")-$(basename "${source[0]}" .tar.gz)"

prepare() {
  cd "$_dirname"
  patch -Np1 -i "$srcdir/hipify-fix-install-cmake.patch"
}

build() {
  local cmake_args=(
                    -B build
                    -S "$_dirname"
                    -Wno-dev
                    -DCMAKE_BUILD_TYPE=None
                    -DCMAKE_INSTALL_PREFIX=/opt/rocm
                   )
  cmake "${cmake_args[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build

  install -Dm644 "$_dirname/LICENSE.txt" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
